﻿<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>SOSOMap_TestSearch</title>
<style type="text/css">
body, button, input, select, textarea {
font: 12px/16px Verdana, Helvetica, Arial, sans-serif;
}
</style>
<script charset="utf-8" src="http://api.map.soso.com/v1.0/main.js"></script>
<script>
var searchService,map,markers = [];
function init(){
    var center = new soso.maps.LatLng(39.916527,116.397128);
	map = new soso.maps.Map(document.getElementById('container'), {
        center: center,
        zoomLevel: 13
    });
	searchService = new soso.maps.SearchService();
}
//清除地图上的marker
function clearOverlays(overlays){
    var overlay;
    while(overlay = overlays.pop()){
        overlay.setMap(null);
    }
}
function searchKeyword() {
    var keyword = document.getElementById("keyword").value;
    var region = document.getElementById("region").value;
    clearOverlays(markers);
    var searchRequest = {
        'keyword': keyword,
        'region':region
    };
    var latlngBounds = new soso.maps.LatLngBounds();
    searchService.search(searchRequest, function(results, status){
		if (status == soso.maps.SearchStatus.OK){
			var pois = results.pois;
			for(var i = 0,l = pois.length;i < l; i++){
				var poi = pois[i];
				latlngBounds.extend(poi.latLng);  
				var marker = new soso.maps.Marker({
					map:map,
					position: poi.latLng
				});
				var decor = new soso.maps.MarkerDecoration({
					content: i+1,
					margin: new soso.maps.Size(0, -4),
					align: soso.maps.ALIGN.CENTER,
					marker: marker
				});        
				markers.push(marker);
			}
			map.fitBounds(latlngBounds);
		} 
		else{
			alert("检索没有结果，原因: " + status);
		}
    });
}
</script>
</head>
<body onload="init();">
<div style="width:650px;height:400px" id="container"></div>
<div>
<input id="keyword" type="textbox" value="酒店">
<input id="region" type="textbox" value="北京">
<input value="搜索" type="button" onclick="searchKeyword();"/>
</div>
</body>
</html>